<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<script type="text/javascript">
    $(function () {
        InitRoleGroup();
        RoleGroupRow();
    });

    function RoleGroupRow() {
        $('#RoleGroup').edatagrid('addRow', {
            row: {
            }
        });
    }
    function InitRoleGroup() {
        $('#RoleGroup').edatagrid({
            //title: '品类信息',
            iconCls: 'icon-site',
            singleSelect: false,
            selectOnCheck: true,
            checkOnSelect: true,
            nowrap: true,
            striped: true,
            collapsible: true,
            remoteSort: true,
            autoSave: true,
            idField: 'groupId',
            url: '<%=basePath%>/system/role/getRoleGroup', //获取数据的url
            columns: [[
               { field: 'groupId', title: '编号', align: 'center', width: '20%'}
              ,{ field: 'name', title: '名称', align: 'center', width: '50%',editor:{type: 'text',required:true } }
            ]],
            toolbar: [
               {
                   text: '添加分组',
                   iconCls: 'icon-add',
                   handler: function () {
                       RoleGroupRow();
                   }
               }
               ,
               {
                   text: '撤销',
                   iconCls: 'icon-cut',
                   handler: function () {
                       $('#RoleGroup').edatagrid('destroyRow');
                   }
               }
            ],
            onAfterEdit: function (rowIndex, rowData, changes)
            {
                var postdata = {
                    groupId: rowData.groupId,
                    name: rowData.name,
                };

                $.post("<%=basePath%>/system/role/saveGroup?id=" + rowData.groupId, postdata, function (data) {
                        loadRoleGroupData();
                });
            },
            });
    }
    function loadRoleGroupData()
    {
        $('#RoleGroup').datagrid('reload');
    }
</script>

<div id="content2" region="center" fit="true">
    <table id="RoleGroup" style="width: 100%"></table>
</div>

